﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    <link rel="StyleSheet" href="/css/cms/main.css?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/css/cms/main.css")) %>"
        type="text/css" />
    <script src="/Scripts/common/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/common/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/Scripts/common/util.js" type="text/javascript"></script>
    <script src="/Scripts/common/form.js" type="text/javascript"></script>
    <script src="/Scripts/cms/main.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/cms/main.js")) %>"
        type="text/javascript"></script>
</head>
<% 
    IList list = (IList)ViewData["sectionlist"];
%>
<script language="JavaScript">
    var sections = { id: 0, state: 1, code: "", name: "", seq: 99, desc: "", parentid: 0, tablename: "", timerinterval: "", fetchsql: "", displaysql: "", manageurl: "", deletesql: "", csid: 0, autodelete: "0"};
    var regular_input = {
        parentid: { exp: /^[\d]+$/, m: "父栏目请输入数字" },
        timerinterval: { exp: /^[\d]*$/, m: "定时器请输入数字" },
        subsite: { exp: /^.+$/, m: "请选择发布站点" },
        code: { exp: /^[A-Za-z0-9_]+$/, m: "栏目编码不能为空，可以是英文字符、数字、下划线" }
    }
    $(document).ready(function () {
        initview();
        //保存栏目信息
        $("input[name='buttEdit']").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(sections, "#mainForm");
            $.post("/cms/checkCode.html", { code: sections.code, id: sections.id }, function (dta) {
                if (dta == '"error"') {
                    alert("编码重复！");
                    return;
                }
                else {
                    sections = $.undoChHtmlTag(sections, ["deletesql", "displaysql", "fetchsql"]);
                    $.post("/cms/SaveSections.html", { sections: $.toJSON(sections) }, function (dta) {
                        alert("设置提交成功");
                        window.parent.frames["leftFrame"].location.reload();
                        location.reload();

                    });
                }
            })
        })
        $("input[name='buttReset']").click();
    })
    function del(id) {
        if (confirm("确认删除？")) {
            $.post("/cms/DelSection.html", { id: id }, function (dta) {
                alert("设置删除成功");
                window.parent.frames["leftFrame"].location.reload();
                location.reload();

            });
        }
    }
    function edit(id) {
        $.post("/cms/getSectionById.html", { id: id }, function (dta) {
            sections = $.evalJSON(dta);
            $.fillForm(sections, "#mainForm");
        });
       
    }

</script>
<body>
    <table cellspacing="0" style="width: 100%">
        <caption style="color: red; font-size: 15px; width: 100%; font-weight: bold">
            栏目列表，此页仅供程序员配置使用 ！！！</caption>
        <tr>
            <th>
                id
            </th>
            <th>
                唯一编码
            </th>
            <th width="120">
                栏目名
            </th>
            <th>
                pid
            </th>
            <th>
                数据表名
            </th>
            <th width="70">
                定时器
            </th>
            <th width="300">
                数据展示规则
            </th>
            <th width="70">
            </th>
        </tr>
        <tbody>
            <%foreach (Hashtable tb in list)
              {
            %>
            <tr style="" tag='<%=tb["id"]%>'>
                <td>
                    <%=tb["id"]%>
                </td>
                <td class="alt">
                    <%=tb["code"]%>
                </td>
                <td title="<%=tb["desc"]%>">
                    <%=tb["name"]%>
                </td>
                <td>
                    <%=tb["parentid"]%>
                </td>
                <td>
                    <%=tb["tablename"]%>
                </td>
                <td>
                    <%if (!String.IsNullOrEmpty(tb["timerinterval"].ToString()))
                      { %><%=tb["timerinterval"]%>分钟<%}
                      else
                      { %>/<%} %>
                </td>
                <td name="displaysql" align="left">
                    <%=tb["displaysql"].ToString().Replace("<" ,"&lt;")%>
                </td>
                <td>
                    <a href="javascript:void(0)" name="linkEdit" onclick='javascript:edit(<%=tb["id"]%>);'>
                        <img border="0" src="/css/cms/images/edit.gif" /></a>&nbsp; <a href="javascript:void(0)"
                            onclick='javascript:del(<%=tb["id"]%>);'>
                            <img border="0" src="/css/cms/images/del.gif" /></a>
                </td>
            </tr>
            <%} %>
            <tbody>
    </table>
    
    <table cellspacing="0" id="mainForm" style="width: 100%">
        <caption>
            新增栏目</caption>
        <tr>
            <th colspan="3">
                新增栏目
            </th>
        </tr>
        <tr>
            <td>
                栏目名称<font color=red>*</font>
            </td>
            <td>
                <input name="name" />
            </td>
            <td>
                <span class="tsxx">按照页面、模块输入易理解的中文名称</span>
            </td>
        </tr>
        <tr>
            <td>
                唯一编码<font color=red>*</font>
            </td>
            <td>
                <input name="code" /><input name="id" type="hidden" vinit="0" />
            </td>
            <td>
                <span class="tsxx">支持英文字符、数字、下划线</span>
            </td>
        </tr>
        <tr>
            <td>
                栏目说明<font color=red>*</font>
            </td>
            <td>
                <textarea name="desc" class="w400"></textarea>
            </td>
            <td>
                <span class="tsxx">支持英文字符、数字、下划线</span>
            </td>
        </tr>
        <tbody id="tb_p" class="xhid">
            <tr>
                <td>
                    父栏目id<font color=red>*</font>
                </td>
                <td>
                    <input name="parentid" vinit="<%=Convert.ToInt32(Request.QueryString["pid"]) %>"/>
                </td>
                <td>
                    <span class="tsxx">必须为数字</span>
                </td>
            </tr>
            <tr>
                <td>
                    数据表名
                </td>
                <td>
                    <input name="tablename" />
                </td>
                <td>
                    <span class="tsxx">仅供显示</span>
                </td>
            </tr>
            <tr>
                <td>
                    定时器(分钟)
                </td>
                <td>
                    <input name="timerinterval" />
                </td>
                <td>
                    <span class="tsxx">设置自动推送程序的执行间隔</span>
                </td>
            </tr>
            <tr>
                <td>
                    数据提取规则
                </td>
                <td>
                    <textarea name="fetchsql" class="w400"></textarea>
                </td>
                <td>
                    <span class="tsxx">输入sql，参数以@param命名</span>
                </td>
            </tr>
            <tr>
                <td>
                    数据展示规则
                </td>
                <td>
                    <textarea name="displaysql" class="w400"></textarea>
                </td>
                <td>
                    <span class="tsxx">输入sql，参数以@param命名</span>
                </td>
            </tr>
            <tr>
                <td>
                    数据删除规则
                </td>
                <td>
                    <textarea name="deletesql" class="w400"></textarea>
                </td>
                <td>
                    <span class="tsxx">输入sql，参数以@param命名</span>
                </td>
            </tr>
            <tr>
                <td>
                    是否自动清除
                </td>
                <td>
                    <input type="radio" name="autodelete" vinit="1" value="1" style="width: 30px">是
                    <input type="radio" vinit="0" name="autodelete" value="0" style="width: 30px" checked>否
                </td>
                <td>
                    <span class="tsxx">选是，则执行数据删除规则</span>
                </td>
            </tr>
            <tr>
                <td>
                    显示排序
                </td>
                <td>
                    <input name="seq" vinit="99" class="w100" />
                </td>
                <td>
                    <span class="tsxx">显示排序</span>
                </td>
            </tr>
            <tr>
                <td>
                    管理地址URL<font color=red>*</font>
                </td>
                <td>
                    <input name="manageurl" class="w400" />
                </td>
                <td>
                    <span class="tsxx">相对路径</span>
                </td>
            </tr>
        </tbody>
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttEdit" class="btn1" style="width: 200px" value="新增" />
                <input type="button" name="buttReset" class="btn1" style="width: 200px" value="重置" />
            </td>
        </tr>
    </table>
</body>
</html>